package com.ciei.dpagm.controller;

import com.alibaba.fastjson.JSONObject;
import com.ciei.dpagm.common.controller.BaseController;
import com.ciei.dpagm.entity.Users;
import com.ciei.dpagm.service.ChipService;
import com.ciei.dpagm.util.PageParam;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangyan
 * @date 2023/05/08
 */
@RestController
@RequestMapping("chip")
public class ChipController extends BaseController {

    @Autowired
    private ChipService chipService;

    @RequestMapping("getChipList")
    public JSONObject getChipList() {
        return chipService.getChipList();
    }

    @RequestMapping("loadChipCategoryList")
    public JSONObject loadChipCategoryList() {
        return chipService.loadChipCategoryList();
    }

    @RequestMapping("loadGrid")
    public JSONObject loadGrid(@RequestBody JSONObject page) {
        PageParam pageParam=getPageParams(page);
        return chipService.loadGrid(pageParam);
    }

    @RequestMapping("getChipInfo")
    public JSONObject getChipInfo(@RequestBody JSONObject query) {
        return chipService.getChipInfo(query);
    }

    @RequiresPermissions("chipLibraryManagement:chipLibrary:add")
    @RequestMapping("addChipByFile")
    public JSONObject addChipByFile(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return chipService.addChipByFile(data,currentUser);
    }

    @RequiresPermissions("chipLibraryManagement:chipLibrary:edit")
    @RequestMapping("updateChipByFile")
    public JSONObject updateChipByFile(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return chipService.updateChipByFile(data,currentUser);
    }

    @RequiresPermissions("chipLibraryManagement:chipLibrary:edit")
    @RequestMapping("update")
    public JSONObject update(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return chipService.update(data,currentUser);
    }

    @RequiresPermissions("chipLibraryManagement:chipLibrary:del")
    @RequestMapping("delete")
    public JSONObject delete(@RequestBody JSONObject data) {
        return chipService.delete(data);
    }

    @RequestMapping("fileRuleCheck")
    @ResponseBody
    public JSONObject fileRuleCheck(@RequestBody JSONObject data) {
        return chipService.fileRuleCheck(data);
    }

    @RequestMapping("loadTree")
    public JSONObject loadTree() {
        return chipService.loadTree();
    }

}
